package com.cefa.edu.controller;

import com.cefa.edu.common.result.FailureResult;
import com.cefa.edu.common.result.Result;
import com.cefa.edu.common.result.ReturnMessage;
import com.cefa.edu.common.result.SuccessResult;
import com.cefa.edu.service.ScoreChainDataService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * Created by cc664 on 2018/8/8.
 */
@RestController
public class ScoreChainDataController {

    //创建slf4j logger实例
    Logger logger= LoggerFactory.getLogger(ScoreChainDataController.class);
    @Autowired
    private ScoreChainDataService scoreChainDataService;


    /**
     * @aa 根据成绩id 获取对应的成绩上链数据
     * @aa add by chaijian
     * @aa data 2018-08-08
     */
    //@RequestMapping("/education/getScoreChainData/scoreId/{scoreId}")
  @RequestMapping(value="/education/getScoreChainData/scoreId",method = RequestMethod.POST)
    public Result<HashMap<String,Object>> getScoreChainDataByScoreId(String scoreId){

        if(StringUtils.isNotBlank(scoreId)){
            HashMap<String,Object> scoreHashData=null;
            FailureResult<HashMap<String, Object>> failureResult= new FailureResult<HashMap<String, Object>>(new ReturnMessage("500","failure"));
           try{
               //判断 页面参数 是否是成绩编号所需格式数据 （即：是否是数字编号）
               Integer sId=Integer.parseInt(scoreId);
             scoreHashData= scoreChainDataService.getScoreChainDataByScoreId(sId);

           }catch(Exception e){
               logger.error("根据成绩编号，获取对应的成绩上链数据时，出错！");
               e.printStackTrace();
               return failureResult;
           }

           //判断scoreHashData 是否为空
            if(scoreHashData==null){
               logger.error("未获取到，该成绩编号 所对应的成绩上链数据！");
                return  failureResult;
            }else{
                return new SuccessResult<HashMap<String, Object>>(new ReturnMessage("200","success"),scoreHashData);
            }
        }
        return null;
    }
}
